// pages/monthlymalldetail/monthlymalldetail.js
var _swit = require('../../utils/swit.js');
var httputil = require('../../utils/httputil.js');

var WxParse = require('../../wxParse/wxParse.js');

Page({
	data: {
		isShowDetail: false,
		scrollTop: 0,
		toview: '',
		goMonthlymallBtn: '立即\n月租',
		detailContent: ''
	},
	onLoad: function (options) {
		// 页面初始化 options为页面跳转所带来的参数
		// var _id = options.id;
		var _this = this;
		httputil.goodsDetail({ 'id': '1' }, {
			success: function (res) {
				var _data = res.data;
				if (_data != null) {
					if (200 == _data.code) {
						var _bean = _data.data;
						console.log(_bean.html);
						_this.data.detailContent = _bean.html;
						// _this.setData({ detailContent: _bean.html })
						//             var that = this;
						// WxParse.wxParse('detailContent', 'html',  _bean.html, that, 5);
						_this.data.detailContent = _this.data.detailContent.replace(/src="/g, "src=\"http://fq.woyes.com");
						WxParse.wxParse('article', 'html', _this.data.detailContent, _this, 5);
					} else {

					}
				} else {

				}
				console.log("success");
			},
			fail: function () {
				console.log("fail");
			},
			complete: function () {
				console.log("complete");


			}
		})
	},
	onReady: function () {
		// 页面渲染完成

	},
	onShow: function () {
		// 页面显示
	},
	onHide: function () {
		// 页面隐藏
	},
	onUnload: function () {
		// 页面关闭
	},
	onClick: function (e) {
		let _id = e.currentTarget.id;
		if ('finddetail' == _id) {
			this.setData({ isShowDetail: true });
			let _this = this;
			setTimeout(function () {
				_this.setData({ toview: 'detailblock' });
			}, 0.01);
		} else if ('gomonthlymall' == _id) {
			let _goMonthlymallBtn = this.data.goMonthlymallBtn;
			if ('立即\n月租' == _goMonthlymallBtn) {
				_swit.swit("../applyforrent/applyforrent");
			} else if ('回到\n顶部' == _goMonthlymallBtn) {
				this.setData({ toview: 'detailblocktop' });
			}
		}
	},
	onScroll: function (e) {
		let _scrollTop = this.data.scrollTop;
		let _currentScrollTop = e.detail.scrollTop;
		if (_scrollTop == 0) {
			this.data.scrollTop = _currentScrollTop;
		}
		var _goMonthlymallBtn = '';
		if (_currentScrollTop >= _scrollTop) {
			_goMonthlymallBtn = '回到\n顶部';
		} else {
			_goMonthlymallBtn = '立即\n月租';
		}
		if (_goMonthlymallBtn != this.data.goMonthlymallBtn) {
			this.setData({ goMonthlymallBtn: _goMonthlymallBtn });
		}
	}
})